package com.football;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class CaptureActivity extends Activity {

	private static final int VIDEO_CAPTURE = 101;
	private Uri fileUri;
	
	@Override 
	protected void onStart() {
		super.onStart();
		Button recordButton = 
                (Button) findViewById(R.id.recordButton);
		
		if (!hasCamera())
			recordButton.setEnabled(false);

	}

	private boolean hasCamera() {
	    if (getPackageManager().hasSystemFeature(
                       PackageManager.FEATURE_CAMERA_ANY)){
	        return true;
	    } else {
	        return false;
	    }
	}
	
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {	    
	    if (requestCode == VIDEO_CAPTURE) {
	        if (resultCode == RESULT_OK) {
	             Toast.makeText(this, "Video has been saved to:\n" +
	                data.getData(), Toast.LENGTH_LONG).show();
	        } else if (resultCode == RESULT_CANCELED) {
	        	Toast.makeText(this, "Video recording cancelled.", 
                      Toast.LENGTH_LONG).show();
	        } else {
	        	Toast.makeText(this, "Failed to record video", 
                      Toast.LENGTH_LONG).show();
	        }
	    }
	}
	
	public void startRecording(View view)
	{
	    File mediaFile = new
       File(Environment.getExternalStorageDirectory().getAbsolutePath() 
              + "/myvideo.mp4");	
	
	    Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
	    fileUri = Uri.fromFile(mediaFile);
		
 	    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
	    startActivityForResult(intent, VIDEO_CAPTURE);
	}

}